﻿// <copyright file="Vector3DConverter.cs" company="Axelerate Solutions S.A.">
// Copyright (c) Axelerate Solutions S.A.  All rights reserved.
// </copyright>

namespace Axelerate.Silverlight3D.Media.Media3D
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.ComponentModel;

    public class Vector3DConverter : TypeConverter
    {
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if (sourceType.Equals(typeof(string)))
            {
                return true;
            }
            else if (sourceType.Equals(typeof(Vector3D)))
            {
                return true;
            }
            else if (sourceType.Equals(typeof(Point3D)))
            {
                return true;
            }
            return false;
        }
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            if (destinationType.Equals(typeof(string)))
            {
                return true;
            }
            else if (destinationType.Equals(typeof(Vector3D)))
            {
                return true;
            }
            else if (destinationType.Equals(typeof(Point3D)))
            {
                return true;
            }
            return false;
        }
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value != null)
            {
                if (value is string)
                {
                    return Vector3D.Parse((string)value);
                }
                else if (value is Vector3D)
                {
                    return (Vector3D)value;
                }
                else if (value is Point3D)
                {
                    return (Vector3D)value;
                }
            }
            return base.ConvertFrom(context, culture, value);
        }
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType.Equals(typeof(string)))
            {
                if (value != null)
                {
                    return ((Vector3D)value).ToString();
                }
            }
            else if (destinationType.Equals(typeof(Point3D)))
            {
                if (value != null)
                {
                    return (Point3D)value;
                }
            }
            return null;
        }
        
    }
}
